//
//  NotView.swift
//  NewWeiBo
//
//  Created by 吴天益 on 2017/7/23.
//  Copyright © 2017年 ttt. All rights reserved.
//

import UIKit
import SnapKit

class NotView: UIView {
    
    var logInBlock: (()->())?
    var logUpBlock: (()->())?
    
    //图片
    private lazy var circleImgV: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
    private lazy var putImgV: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_mask_smallicon"))
    private lazy var homeImgV: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
    
    //lable
    private lazy var firstLab: UILabel = {
        let fLab = UILabel()
        fLab.text = "home控制器"
        fLab.textAlignment = .center
        fLab.font = UIFont.systemFont(ofSize: 14)
        fLab.textColor = UIColor.darkGray
        return fLab
    }()
    
    private lazy var secondLab: UILabel = {
        let sLab = UILabel()
        sLab.text = "第一个控制器"
        sLab.textAlignment = .center
        sLab.font = UIFont.systemFont(ofSize: 14)
        sLab.textColor = UIColor.darkGray
        return sLab
    }()
    
    //登陆按钮
    private lazy var loginBtn: UIButton = {
        let logInBtn = UIButton()
        
        logInBtn.addTarget(self, action: #selector(logIn), for: .touchUpInside)
        
        logInBtn.setTitle("登陆", for: .normal)
        logInBtn.setTitleColor(UIColor.darkGray, for: .normal)
        logInBtn.setTitleColor(UIColor.orange, for: .highlighted)
        
        //图片拉升
        let image = UIImage(named: "common_button_white_disable")?.stretchableImage(withLeftCapWidth: 5, topCapHeight: 5)
        
        logInBtn.setBackgroundImage(image, for: .normal)
        
        //取消按钮默认点击高亮
        logInBtn.adjustsImageWhenHighlighted = false
        return logInBtn
    }()
    
    //注册按钮
    private lazy var logUpBtn: UIButton = {
        let logUpBtn = UIButton()
        
        logUpBtn.addTarget(self, action: #selector(logUp), for: .touchUpInside)

        logUpBtn.setTitle("注册", for: .normal)
        logUpBtn.setTitleColor(UIColor.darkGray, for: .normal)
        logUpBtn.setTitleColor(UIColor.orange, for: .highlighted)
        
        //图片拉升
        let image = UIImage(named: "common_button_white_disable")?.stretchableImage(withLeftCapWidth: 5, topCapHeight: 5)
        
        logUpBtn.setBackgroundImage(image, for: .normal)
        
        logUpBtn.adjustsImageWhenHighlighted = false
        return logUpBtn
        
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    //MARK: - 登陆按钮方法
    func logIn(){
        
        logInBlock?()
    }
    
    //MARK: - 注册按钮方法
    func logUp(){
        
        logUpBlock?()
    }
 
    //MARK: - 界面制作
    func setupUI(){
        backgroundColor = UIColor.init(red: 0.93, green: 0.93, blue: 0.93, alpha: 1.00)
        
        addSubview(circleImgV)
        addSubview(putImgV)
        addSubview(homeImgV)
        addSubview(firstLab)
        addSubview(secondLab)
        addSubview(loginBtn)
        addSubview(logUpBtn)
        
        circleImgV.snp.makeConstraints { (make) in
            make.center.equalTo(self)
        }
        putImgV.snp.makeConstraints { (make) in
            make.center.equalTo(self)
        }
        homeImgV.snp.makeConstraints { (make) in
            make.center.equalTo(self)
        }
        firstLab.snp.makeConstraints { (make) in
            make.top.equalTo(circleImgV.snp.bottom).offset(10)
            make.centerX.equalTo(self)
        }
        secondLab.snp.makeConstraints { (make) in
            make.top.equalTo(firstLab.snp.bottom).offset(10)
            make.centerX.equalTo(self)
        }
        loginBtn.snp.makeConstraints { (make) in
            make.top.equalTo(secondLab.snp.bottom).offset(10)
            make.left.equalTo(putImgV)
        }
        logUpBtn.snp.makeConstraints { (make) in
            make.top.equalTo(loginBtn)
            make.right.equalTo(putImgV)
        }
        
        //添加circleImgV的动画
        let animation = CABasicAnimation(keyPath: "transform.rotation")
        
        //动画目的地
        animation.toValue = 2 * Double.pi
        
        //动画执行一次持续时间
        animation.duration = 20
        
        //动画执行次数
        animation.repeatCount = MAXFLOAT
        
        //***切换控制器失去焦点是,不释放动画
        animation.isRemovedOnCompletion = false
        
        //执行动画
        circleImgV.layer.add(animation, forKey: nil)
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        print(circleImgV.center)
        print(circleImgV)
    }
    
    
    //MARK: - 不是home控制器的修改访问者界面的方法
    func theUIOfOtherController(imageName: String,discribe: String){
        
        circleImgV.isHidden = true
        
        homeImgV.image = UIImage(named: imageName)
        
        secondLab.text = discribe
    }
}
